package jing.ej.generic.method;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class GenericMethod {
	// Uses raw types - unacceptable! (Item 23)
	public static Set raw_union(Set s1, Set s2) {
		Set result = new HashSet(s1);
		result.addAll(s2);
		return result;
	}
	
	// Generic method
	public static <E> Set<E> generic_union(Set<E> s1, Set<E> s2) {
		Set<E> result = new HashSet<E>(s1);
		result.addAll(s2);
		return result;
	}
	
	public static void main(String[] args) {
		Set<String> guys = new HashSet<String>(
		Arrays.asList("Tom", "Dick", "Harry"));
		Set<String> stooges = new HashSet<String>(
		Arrays.asList("Larry", "Moe", "Curly"));
		Set<String> aflCio = generic_union(guys, stooges);
		System.out.println(aflCio);
	}
}


